<?php   
    /* 
    Plugin Name: Wordpress Bittorrent (WPBT) Lite
    Plugin URI: http://code.google.com/p/wpbt/
    Description: Plugin for sharing files from Wordpress using Bittorrent. 
    Author: Jay M.
    Version: 0.1
    Author URI: http://www.jayakumar.co.in/
    License: GPL 
    */  
	
	include('wpbt_attach_info.php');
	include('wpbt_allttable.php');
	require_once('lib/File/Bittorrent2/Decode.php');
	require_once('lib/File/Bittorrent2/Encode.php');	
	
	function wpbt_admin() {
		include('wpbt_config_admin.php');
	}

	function wpbt_admin_actions() {
		add_options_page("WPBT Lite", "WPBT Lite", 1, "WPBT-Lite", "wpbt_admin");
	}

	// Setting up WP Admin menu
	add_action('admin_menu', 'wpbt_admin_actions');

	// Load custom css 
	add_action('wp_head', 'wpbt_get_css');

	// Add mime support for .torrent files
	add_filter('upload_mimes','add_tor_to_upload_mimes');

	// Add torrent information to posts with .torrent files attached
	add_filter('the_content', 'get_attachments_info');

	// Create a Special "torrents/browse/download" page with information of all the .torrent files attached to all the posts on the blog
	add_filter('the_content', 'create_alltorrent_table');

	// Add in torrent mime-type to the supplied array
	// You could modify the mime_types array to add additional mime-types if you wish to.
	function add_tor_to_upload_mimes()	{
		$mime_types = array (
			'torrent' => 'application/x-bittorrent',
			'jpg' => 'image/jpeg'
			);
		return $mime_types; 
	}

	function modify_post_mime_types($post_mime_types) {
			$post_mime_types['application/x-bittorrent'] = array(__('Torrents', 'swfobj'), __('Manage Torrents', 'swfobj'), __ngettext_noop('Torrents (%s)', 'Torrents (%s)', 'swfobj'));
		return $post_mime_types;
	}

	add_filter('post_mime_types', 'modify_post_mime_types');
	

/*  MakeTorrent from with in wordpress, Work-in-progress, hence disabled

	add_filter( 'manage_media_columns', 'mediaColumnsHeader' );
	add_filter( 'manage_media_custom_column', 'mediaColumnsRow', 10, 2 );
	function mediaColumnsHeader($columns) {
			$columns['medID'] = __('MakeTorrent');
		return $columns;
	}
	
	function mediaColumnsRow($columnName, $columnID){
		if($columnName == 'medID'){
		
		$attachment = get_post_mime_type($columnID);
			
			if ($attachment !=  'application/x-bittorrent') {
							
				echo '<a href="'. get_bloginfo("wpurl") . "/wp-admin/upload.php?page=wpbtlite/wpbtlite.php&action=maketorrentc&attachment_id=".$columnID.'"><img src="/wp-content/plugins/wpbtlite/images/files.gif" alt="MakeATorrent" title="MakeATorrent"></a>';
			}
			else {
				echo '<a href="'. wp_get_attachment_url($columnID).'"><img src="/wp-content/plugins/wpbtlite/images/download.gif" alt="IsATorrent" title="IsATorrent"></a>';
			}
		
			//echo $columnID;
		}
	}
*/
	

	
	/**
	 * Echos the link to the plugin stylesheet
	 */
	function wpbt_get_css() {
		$css_file = path_join(get_plugin_url(),'css/wpbt.css');
		echo "<link rel=\"stylesheet\" href=\"{$css_file}\" type=\"text/css\" />";
	}
	
	function get_plugin_url() {
		if ( !defined('WP_PLUGIN_URL') ) {
			define( 'WP_PLUGIN_URL', WP_CONTENT_URL . '/plugins' ); // full url, no trailing slash
		}
		$pluginUrl = path_join(WP_PLUGIN_URL, dirname(plugin_basename(__FILE__)));
		return $pluginUrl;
	}




?>